"use strict";
function _slicedToArray(t, e) {
    return _arrayWithHoles(t) || _iterableToArrayLimit(t, e) || _unsupportedIterableToArray(t, e) || _nonIterableRest()
}
function _nonIterableRest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
}
function _unsupportedIterableToArray(t, e) {
    var n;
    if (t)
        return "string" == typeof t ? _arrayLikeToArray(t, e) : "Map" === (n = "Object" === (n = Object.prototype.toString.call(t).slice(8, -1)) && t.constructor ? t.constructor.name : n) || "Set" === n ? Array.from(t) : "Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? _arrayLikeToArray(t, e) : void 0
}
function _arrayLikeToArray(t, e) {
    (null == e || e > t.length) && (e = t.length);
    for (var n = 0, o = new Array(e); n < e; n++)
        o[n] = t[n];
    return o
}
function _iterableToArrayLimit(t, e) {
    var n = null == t ? null : "undefined" != typeof Symbol && t[Symbol.iterator] || t["@@iterator"];
    if (null != n) {
        var o, r, a, i, l = [], c = !0, d = !1;
        try {
            if (a = (n = n.call(t)).next,
            0 === e) {
                if (Object(n) !== n)
                    return;
                c = !1
            } else
                for (; !(c = (o = a.call(n)).done) && (l.push(o.value),
                l.length !== e); c = !0)
                    ;
        } catch (t) {
            d = !0,
            r = t
        } finally {
            try {
                if (!c && null != n.return && (i = n.return(),
                Object(i) !== i))
                    return
            } finally {
                if (d)
                    throw r
            }
        }
        return l
    }
}
function _arrayWithHoles(t) {
    if (Array.isArray(t))
        return t
}
var btf = {
    debounce: function(r) {
        var a, i = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : 0, l = 2 < arguments.length && void 0 !== arguments[2] && arguments[2];
        return function() {
            for (var t = arguments.length, e = new Array(t), n = 0; n < t; n++)
                e[n] = arguments[n];
            var o = l && !a;
            clearTimeout(a),
            a = setTimeout(function() {
                a = null,
                l || r.apply(void 0, e)
            }, i),
            o && r.apply(void 0, e)
        }
    },
    throttle: function(a, i) {
        function l() {
            m = !1 === f.leading ? 0 : (new Date).getTime(),
            c = null,
            a.apply(d, s),
            c || (d = s = null)
        }
        var c, d, s, u = this, f = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : {}, m = 0;
        return function() {
            var t = (new Date).getTime()
              , e = (m || !1 !== f.leading || (m = t),
            i - (t - m));
            d = u;
            for (var n = arguments.length, o = new Array(n), r = 0; r < n; r++)
                o[r] = arguments[r];
            s = o,
            e <= 0 || i < e ? (c && (clearTimeout(c),
            c = null),
            m = t,
            a.apply(d, s),
            c || (d = s = null)) : c || !1 === f.trailing || (c = setTimeout(l, e))
        }
    },
    sidebarPaddingR: function() {
        var t = window.innerWidth
          , e = document.body.clientWidth;
        t !== e && (document.body.style.paddingRight = t - e + "px")
    },
    snackbarShow: function(t) {
        var e = 1 < arguments.length && void 0 !== arguments[1] && arguments[1]
          , n = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : 2e3
          , o = GLOBAL_CONFIG.Snackbar
          , r = o.position
          , a = o.bgLight
          , o = o.bgDark
          , a = "light" === document.documentElement.getAttribute("data-theme") ? a : o;
        Snackbar.show({
            text: t,
            backgroundColor: a,
            showAction: e,
            duration: n,
            pos: r,
            customClass: "snackbar-css"
        })
    },
    diffDate: function(t) {
        var e, n, o, r = 1 < arguments.length && void 0 !== arguments[1] && arguments[1], a = new Date, t = new Date(t), a = a.getTime() - t.getTime(), i = GLOBAL_CONFIG.dateSuffix;
        return r ? (r = a / 864e5,
        n = a / 36e5,
        o = a / 6e4,
        12 < (e = a / 2592e6) ? t.toISOString().slice(0, 10) : 1 <= e ? "".concat(parseInt(e), " ").concat(i.month) : 1 <= r ? "".concat(parseInt(r), " ").concat(i.day) : 1 <= n ? "".concat(parseInt(n), " ").concat(i.hour) : 1 <= o ? "".concat(parseInt(o), " ").concat(i.min) : i.just) : parseInt(a / 864e5)
    },
    loadComment: function(t, e) {
        var n;
        "IntersectionObserver"in window ? (n = new IntersectionObserver(function(t) {
            t[0].isIntersecting && (e(),
            n.disconnect())
        }
        ,{
            threshold: [0]
        })).observe(t) : e()
    },
    scrollToDest: function(n) {
        var o, r = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : 500, a = window.pageYOffset, t = document.getElementById("page-header").classList.contains("fixed");
        (n < a || t) && (n -= 70),
        "scrollBehavior"in document.documentElement.style ? window.scrollTo({
            top: n,
            behavior: "smooth"
        }) : (o = null,
        n = +n,
        window.requestAnimationFrame(function t(e) {
            e -= o = o || e;
            a < n ? window.scrollTo(0, (n - a) * e / r + a) : window.scrollTo(0, a - (a - n) * e / r),
            e < r ? window.requestAnimationFrame(t) : window.scrollTo(0, n)
        }))
    },
    animateIn: function(t, e) {
        t.style.display = "block",
        t.style.animation = e
    },
    animateOut: function(e, t) {
        e.addEventListener("animationend", function t() {
            e.style.display = "",
            e.style.animation = "",
            e.removeEventListener("animationend", t)
        }),
        e.style.animation = t
    },
    wrap: function(t, e, n) {
        for (var o = document.createElement(e), r = 0, a = Object.entries(n); r < a.length; r++) {
            var i = _slicedToArray(a[r], 2)
              , l = i[0]
              , i = i[1];
            o.setAttribute(l, i)
        }
        t.parentNode.insertBefore(o, t),
        o.appendChild(t)
    },
    isHidden: function(t) {
        return 0 === t.offsetHeight && 0 === t.offsetWidth
    },
    getEleTop: function(t) {
        for (var e = t.offsetTop, n = t.offsetParent; null !== n; )
            e += n.offsetTop,
            n = n.offsetParent;
        return e
    },
    loadLightbox: function(t) {
        var e = GLOBAL_CONFIG.lightbox;
        "mediumZoom" === e && mediumZoom(t, {
            background: "var(--zoom-bg)"
        }),
        "fancybox" === e && (Array.from(t).forEach(function(t) {
            var e, n;
            "A" !== t.parentNode.tagName && (e = t.dataset.lazySrc || t.src,
            n = t.title || t.alt || "",
            btf.wrap(t, "a", {
                href: e,
                "data-fancybox": "gallery",
                "data-caption": n,
                "data-thumb": e
            }))
        }),
        window.fancyboxRun || (Fancybox.bind("[data-fancybox]", {
            Hash: !1,
            Thumbs: {
                showOnStart: !1
            },
            Images: {
                Panzoom: {
                    maxScale: 4
                }
            },
            Carousel: {
                transition: "slide"
            },
            Toolbar: {
                display: {
                    left: ["infobar"],
                    middle: ["zoomIn", "zoomOut", "toggle1to1", "rotateCCW", "rotateCW", "flipX", "flipY"],
                    right: ["slideshow", "thumbs", "close"]
                }
            }
        }),
        window.fancyboxRun = !0))
    },
    setLoading: {
        add: function(t) {
            t.insertAdjacentHTML("afterend", '\n        <div class="loading-container">\n          <div class="loading-item">\n            <div></div><div></div><div></div><div></div><div></div>\n          </div>\n        </div>\n      ')
        },
        remove: function(t) {
            t.nextElementSibling.remove()
        }
    },
    updateAnchor: function(t) {
        var e;
        t !== window.location.hash && (t = t || location.pathname,
        e = GLOBAL_CONFIG_SITE.title,
        window.history.replaceState({
            url: location.href,
            title: e
        }, e, t))
    },
    getScrollPercent: function(t, e) {
        var n = e.clientHeight
          , o = document.documentElement.clientHeight
          , e = e.offsetTop
          , n = o < n ? n - o : document.documentElement.scrollHeight - o
          , o = Math.round(100 * ((t - e) / n));
        return 100 < o ? 100 : o <= 0 ? 0 : o
    },
    addGlobalFn: function(t, e) {
        var n = 2 < arguments.length && void 0 !== arguments[2] && arguments[2]
          , o = 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : window
          , r = o.globalFn || {}
          , a = r[t] || {};
        n && a[n] || (a[n || Object.keys(a).length] = e,
        r[t] = a,
        o.globalFn = r)
    },
    addEventListenerPjax: function(t, e, n) {
        var o = 3 < arguments.length && void 0 !== arguments[3] && arguments[3];
        t.addEventListener(e, n, o),
        btf.addGlobalFn("pjax", function() {
            t.removeEventListener(e, n, o)
        })
    },
    removeGlobalFnEvent: function(t) {
        var e = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : window
          , n = e.globalFn
          , o = (void 0 === n ? {} : n)[t] || {}
          , n = Object.keys(o);
        n.length && (n.forEach(function(t) {
            o[t]()
        }),
        delete e.globalFn[t])
    }
};
